#include "NetworkClient.h"

namespace mp_net
{


	NetworkClient::NetworkClient()
		:NetworkSession()
	{
		m_resolver = NULL;
	}

	NetworkClient::~NetworkClient()
	{
		//Lock for cleanup, 
		//NetworkSession calls Unlock
		while(!TryLock()){;}

		StopOperatingThread();

		delete m_resolver;
	}

	void NetworkClient::Initialize()
	{
		
	}

	void NetworkClient::Update()
	{
		
	}

	void NetworkClient::Uninitialize()
	{
		
	}
		
	void NetworkClient::Start()
	{
		m_ioService.run();
		
		m_socket = socket_ptr(new tcp::socket(m_ioService));
		m_resolver = new tcp::resolver(m_ioService);

		tcp::endpoint ep(boost::asio::ip::address_v4(0xC0A80104), NET_SESSION_DEF_PORT); 
		tcp::resolver::iterator iterator = m_resolver->resolve(ep);
		m_socket->connect(*iterator);

		//Start the operating thread
		StartOperatingThread();

	}

	void NetworkClient::NetThreadProc()
	{
		while (!m_stopRequested)
		{
			int z = 1;
		}
	}

}